home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
PVDRIVER
/
GSVIEW10.ZIP
/
PS.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-04-23
|
45KB
|
1,379 lines
/*
* ps.c -- Postscript scanning and copying routines.
* Copyright (C) 1992 Timothy O. Theisen
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Tim Theisen Systems Programmer
* Internet: tim@cs.wisc.edu Department of Computer Sciences
* UUCP: uwvax!tim University of Wisconsin-Madison
* Phone: (608)262-0438 1210 West Dayton Street
* FAX: (608)262-9777 Madison, WI 53706
*
* This file has been modified by Russell Lang (rjl@monu1.cc.monash.edu.au)
* 1993-04-23
* - Header file includes changed for MS-Windows.
* - MS-DOS carriage return handling added.
* - Ignore ^D as first character of file
* - Allow %%Pages: 0
*/
#include <stdio.h>
#ifdef __TURBOC__
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define strcasecmp(s,t) stricmp(s,t)
extern void pserror(char *str);
#else
#ifndef SEEK_SET
#define SEEK_SET 0
#endif
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif
#include <ctype.h>
#include <X11/Xos.h> /* #includes the appropriate <string.h> */
#define pserror(str) fprintf(stderr,str)
#endif
#include "ps.h"
#ifdef BSD4_2
#define memset(a,b,c) bzero(a,c)
#endif
/* length calculates string length at compile time */
/* can only be used with character constants */
#define length(a) (sizeof(a)-1)
#define iscomment(a, b) (strncmp(a, b, length(b)) == 0)
/* list of standard paper sizes from Adobe's PPD. */
struct documentmedia papersizes[] = {
"Letter", 612, 792,
"LetterSmall", 612, 792,
"Tabloid", 792, 1224,
"Ledger", 1224, 792,
"Legal", 612, 1008,
"Statement", 396, 612,
"Executive", 540, 720,
"A3", 842, 1190,
"A4", 595, 842,
"A4Small", 595, 842,
"A5", 420, 595,
"B4", 729, 1032,
"B5", 516, 729,
"Folio", 612, 936,
"Quarto", 610, 780,
"10x14", 720, 1008,
NULL, 0, 0
};
static char *readline();
static char *gettextline();
static char *gettext();
static int blank();
/*
* psscan -- scan the PostScript file for document structuring comments.
*
* This scanner is designed to retrieve the information necessary for
* the ghostview previewer. It will scan files that conform to any
* version (1.0, 2.0, 2.1, or 3.0) of the document structuring conventions.
* It does not really care which version of comments the file contains.
* (The comments are largely upward compatible.) It will scan a number
* of non-conforming documents. (You could have part of the document
* conform to V2.0 and the rest conform to V3.0. It would be similar
* to the DC-2 1/2+, it would look funny but it can still fly.)
*
* This routine returns a pointer to the document structure.
* The structure contains the information relevant to previewing.
* These include EPSF flag (to tell if the file is a encapsulated figure),
* Page Media (for the Page Size), Bounding Box (to minimize backing
* pixmap size or determine window size for encapsulated PostScript),
* Orientation of Paper (for default transformation matrix), and
* Page Order. The title and CreationDate are also retrieved to
* help identify the document.
*
* The following comments are examined:
*
* Header section:
* Must start with %!PS-Adobe-. Version numbers ignored.
*
* %!PS-Adobe-* [EPSF-*]
* %%BoundingBox: <int> <int> <int> <int>|(atend)
* %%CreationDate: <textline>
* %%Orientation: Portrait|Landscape|(atend)
* %%Pages: <uint> [<int>]|(atend)
* %%PageOrder: Ascend|Descend|Special|(atend)
* %%Title: <textline>
* %%DocumentMedia: <text> <real> <real> <real> <text> <text>
* %%DocumentPaperSizes: <text>
* %%EndComments
*
* Note: Either the 3.0 or 2.0 syntax for %%Pages is accepted.
* Also either the 2.0 %%DocumentPaperSizes or the 3.0
* %%DocumentMedia comments are accepted as well.
*
* The header section ends either explicitly with %%EndComments or
* implicitly with any line that does not begin with %X where X is
* a not whitespace character.
*
* If the file is encapsulated PostScript the optional Preview section
* is next:
*
* %%BeginPreview
* %%EndPreview
*
* This section explicitly begins and ends with the above comments.
*
* Next the Defaults section for version 3 page defaults:
*
* %%BeginDefaults
* %%PageBoundingBox: <int> <int> <int> <int>
* %%PageOrientation: Portrait|Landscape
* %%PageMedia: <text>
* %%EndDefaults
*
* This section explicitly begins and ends with the above comments.
*
* The prolog section either explicitly starts with %%BeginProlog or
* implicitly with any nonblank line.
*
* %%BeginProlog
* %%EndProlog
*
* The Prolog should end with %%EndProlog, however the proglog implicitly
* ends when %%BeginSetup, %%Page, %%Trailer or %%EOF are encountered.
*
* The Setup section is where the version 2 page defaults are found.
* This section either explicitly begins with %%BeginSetup or implicitly
* with any nonblank line after the Prolog.
*
* %%BeginSetup
* %%PageBoundingBox: <int> <int> <int> <int>
* %%PageOrientation: Portrait|Landscape
* %%PaperSize: <text>
* %%EndSetup
*
* The Setup should end with %%EndSetup, however the setup implicitly
* ends when %%Page, %%Trailer or %%EOF are encountered.
*
* Next each page starts explicitly with %%Page and ends implicitly with
* %%Page or %%Trailer or %%EOF. The following comments are recognized:
*
* %%Page: <text> <uint>
* %%PageBoundingBox: <int> <int> <int> <int>|(atend)
* %%PageOrientation: Portrait|Landscape
* %%PageMedia: <text>
* %%PaperSize: <text>
*
* The tralier section start explicitly with %%Trailer and end with %%EOF.
* The following comment are examined with the proper (atend) notation
* was used in the header:
*
* %%Trailer
* %%BoundingBox: <int> <int> <int> <int>|(atend)
* %%Orientation: Portrait|Landscape|(atend)
* %%Pages: <uint> [<int>]|(atend)
* %%PageOrder: Ascend|Descend|Special|(atend)
* %%EOF
*
*
* + A DC-3 received severe damage to one of its wings. The wing was a total
* loss. There was no replacement readily available, so the mechanic
* installed a wing from a DC-2.
*/
struct document *
psscan(file)
FILE *file;
{
struct document *doc;
int bb_set = NONE;
int pages_set = NONE;
int page_order_set = NONE;
int orientation_set = NONE;
int page_bb_set = NONE;
int page_media_set = NONE;
int preread; /* flag which tells the readline isn't needed */
int i;
unsigned int maxpages = 0;
unsigned int nextpage = 1; /* Next expected page */
unsigned int thispage;
int ignore = 0; /* whether to ignore page ordinals */
char *label;
char line[PSLINELENGTH]; /* 255 characters + 1 newline + 1 NULL */
char text[PSLINELENGTH]; /* Temporary storage for text */
long position; /* Position of the current line */
unsigned int line_len; /* Length of the current line */
unsigned int section_len; /* Place to accumulate the section length */
char *next_char;